let ajaxTime = 0

export function request(params) {
  ajaxTime++
  wx.showLoading({
    title: '加载中',
  })
  return new Promise((resolve, reject) => {
    wx.request({
      ...params,
      url: 'https://api-hmugo-web.itheima.net/api/public/v1/' + params.url,
      success: (result) => {
        resolve(result)
      },
      fail: (err) => {
        reject(err)
      },
      complete: () => {
        ajaxTime--
        if (ajaxTime === 0) {
          wx.hideLoading()
        }
      }
    });
  })
}